package com.hckj.medical.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hckj.medical.entity.Booking;
import com.hckj.medical.mapper.BookingMapper;
import com.hckj.medical.service.IBookingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hckj
 * @since 2023-11-25
 */
@Service
public class BookingServiceImpl extends ServiceImpl<BookingMapper, Booking> implements IBookingService {

    @Autowired
    private BookingMapper bookingMapper;

    @Override
    public List<Map> findAllBydocId(Map map) {
        return bookingMapper.selectAllByDid(map);
    }
    @Override
    public List<Booking> selectBookingByidAnddepartment(Integer id, Integer department) {
        return bookingMapper.selectBookingByidAnddepartment(id,department);
    }

    @Override
    public Integer InsertBooking(Booking booking) {
        return  bookingMapper.insert(booking);
    }

    @Override
    public Booking selectBookingById(Integer id) {
        return bookingMapper.selectById(id);
    }

    @Override
    public Integer updatebstatus(Booking booking) {
        return bookingMapper.updateById(booking);
    }

    @Override
    public Integer updateBooking(Booking booking) {
        return bookingMapper.updateById(booking);
    }



    @Override
    public List<Booking> selectBookingBybstatus(List bstatus,Integer userid) {
        QueryWrapper<Booking> bookingQueryWrapper = new QueryWrapper<>();
        bookingQueryWrapper.in("bstatus",bstatus);
        bookingQueryWrapper.eq("userid",userid);
        bookingQueryWrapper.orderByDesc("reviewtime");
        return bookingMapper.selectList(bookingQueryWrapper);
    }

    @Override
    public Integer updateBookingyy(Booking booking) {
        return bookingMapper.updateById(booking);
    }

    @Override
    public Page<Map> findAllByuser(Map map) {
        Integer pageNo = (Integer)map.get("pageNo");
        Integer pageSize = (Integer)map.get("pageSize");
        Page<Map> page = new Page<>(pageNo,pageSize);
        return bookingMapper.findAllBooking(page,map);
    }

    @Override
    public Map findByid(Integer id) {
        return bookingMapper.selectByid(id);
    }

    @Override
    public void updateByid(Booking booking) {
        bookingMapper.updateById(booking);
    }
}
